package com.smart.village.big.screen.controller.bigscreen;

import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.SafeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 数智安全数据接口
 */
@Tag(name = "数智安全数据接口")
@RestController
@RequestMapping("/safe")
public class SafeController {
    Logger logger = Logger.getLogger(SafeController.class.getName());

    @Autowired
    private SafeService safeService;



    /**
     * 获取大屏 数智安全 巡防任务
     *
     * @return
     */
    @Operation(summary = "获取大屏 数智安全 巡防任务")
    @Parameters({
            @Parameter(name = "type", description = "类型 必传 week,month,year"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),

    })
    @GetMapping("/getPatrolTaskPlan")
    @ResponseBody
    public AjaxResult getPatrolTaskPlan(
            @RequestParam String type,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return success(safeService.getPatrolTaskPlan(type, townNumber, villageNumber, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 数智安全 巡防任务-轨迹坐标
     *
     * @return
     */
    @Operation(summary = "获取大屏 数智安全 巡防任务-轨迹坐标")
    @Parameters({
            @Parameter(name = "taskSerialNumber", description = "任务编码 必传"),
            @Parameter(name = "taskPlanSerialNumber", description = "任务计划编码 必传"),

    })
    @GetMapping("/getPatrolTaskPlanCoords")
    @ResponseBody
    public AjaxResult getPatrolTaskPlanCoords(
            @RequestParam String taskSerialNumber,
            @RequestParam String taskPlanSerialNumber

    ) {
        try {
            return success(safeService.getPatrolTaskPlanCoords(taskSerialNumber, taskPlanSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 数智安全 异常报警
     *
     * @return
     */
    @Operation(summary = "获取大屏 数智安全 异常报警")
    @Parameters({
            @Parameter(name = "source", description = "类型 必传 小程序-边境巡逻"),
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getExceptionTip")
    @ResponseBody
    public AjaxResult getExceptionTip(
            @RequestParam String source,
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(safeService.getExceptionTip(source, townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 获取大屏 数智安全 巡逻管理
     *
     * @return
     */
    @Operation(summary = "获取大屏 数智安全 巡逻管理")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getPatrolManager")
    @ResponseBody
    public AjaxResult getPatrolManager(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false, defaultValue = "") String villageNumber
    ) {
        try {
            return success(safeService.getPatrolManager(townNumber, villageNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    @Operation(summary = "地图信息")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getSafeCoordsList")
    @ResponseBody
    public AjaxResult getShopCoordsList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        return AjaxResult.success(safeService.getSafeCoordsList(townNumber, villageNumber));
    }

    @Operation(summary = "地图图例 ")
    @GetMapping("/getSafeTagsList")
    @ResponseBody
    public AjaxResult getSafeTagsList(
    ) {

        return AjaxResult.success(safeService.getSafeTagsList());
    }

    @Operation(summary = "视频监控 ")
    @GetMapping("/getMonitorDeviceList")
    @ResponseBody
    public AjaxResult getMonitorDeviceList(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber,
            @RequestParam(required = false) String usageTypeSerialNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {

        return AjaxResult.success(safeService.getMonitorDeviceList(townNumber, villageNumber, usageTypeSerialNumber, pageNum, pageSize));
    }

    @Operation(summary = "摄像头用途 列表")
    @GetMapping("/getMonitorDeviceUsageTypeList")
    @ResponseBody
    public AjaxResult getMonitorDeviceUsageTypeList(
    ) {

        return AjaxResult.success(safeService.getMonitorDeviceUsageTypeList());
    }

    @Operation(summary = "安全评估")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getSafeAssess")
    @ResponseBody
    public AjaxResult getSafeAssess(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        return AjaxResult.success(safeService.getSafeAssess(townNumber, villageNumber));
    }

    @Operation(summary = "安全指数")
    @Parameters({
            @Parameter(name = "townNumber", description = "镇编码 必传"),
            @Parameter(name = "villageNumber", description = "村编码 非必传"),
    })
    @GetMapping("/getSafeIndex")
    @ResponseBody
    public AjaxResult getSafeIndex(
            @RequestParam(required = false) String townNumber,
            @RequestParam(required = false) String villageNumber
    ) {
        return AjaxResult.success(safeService.getSafeIndex(townNumber, villageNumber));
    }
}
